package v1

import (
  "github.com/gin-gonic/gin"
  "pay/bll"
  "pay/model"
  "pay/server/web/middleware"
  "pay/utils"
)

var FeePlanGroupObject = &feePlanGroupObject{}

func init() {
  RegisterRouter(FeePlanGroupObject)
}

type feePlanGroupObject struct{}

// Init
func (a *feePlanGroupObject) Init(r *gin.RouterGroup) {
  g := r.Group("/feePlanGroupObject", middleware.Auth())
  {
    g.POST("/create", a.create)
    g.POST("/update", a.update)
    g.POST("/list", a.list)
    g.POST("/delete", a.delete)
    g.POST("/detail", a.find)
  }
}

// create
func (a *feePlanGroupObject) create(c *gin.Context) {
  var (
    in  = &model.FeePlanGroupObjectCreateRequest{}
    err error
  )

  if err = c.ShouldBindJSON(in); err != nil {
    _ = c.Error(err)
    return
  }

  if err = bll.FeePlanGroupObject.Create(c.Request.Context(), in); err != nil {
    _ = c.Error(err)
    return
  }
  utils.ResponseOk(c, nil)
}

// update
func (a *feePlanGroupObject) update(c *gin.Context) {
  var (
    in  = &model.FeePlanGroupObjectUpdateRequest{}
    err error
  )

  if err = c.ShouldBindJSON(in); err != nil {
    _ = c.Error(err)
    return
  }

  if err = bll.FeePlanGroupObject.Update(c.Request.Context(), in); err != nil {
    _ = c.Error(err)
    return
  }
  utils.ResponseOk(c, nil)
}

// list
func (a *feePlanGroupObject) list(c *gin.Context) {
  var (
    in  = &model.FeePlanGroupObjectListRequest{}
    out = &model.FeePlanGroupObjectListResponse{}
    err error
  )

  if err = c.ShouldBindJSON(in); err != nil {
    _ = c.Error(err)
    return
  }

  if out, err = bll.FeePlanGroupObject.List(c.Request.Context(), in); err != nil {
    _ = c.Error(err)
    return
  }
  utils.ResponseOk(c, out)
}

// list
func (a *feePlanGroupObject) find(c *gin.Context) {
  var (
    in  = &model.FeePlanGroupObjectInfoRequest{}
    out = &model.FeePlanGroupObjectInfo{}
    err error
  )

  if err = c.ShouldBindJSON(in); err != nil {
    _ = c.Error(err)
    return
  }

  if out, err = bll.FeePlanGroupObject.Find(c.Request.Context(), in); err != nil {
    _ = c.Error(err)
    return
  }
  utils.ResponseOk(c, out)
}

// delete
func (a *feePlanGroupObject) delete(c *gin.Context) {
  var (
    in  = &model.FeePlanGroupObjectDeleteRequest{}
    err error
  )

  if err = c.ShouldBindJSON(in); err != nil {
    _ = c.Error(err)
    return
  }

  if err = bll.FeePlanGroupObject.Delete(c.Request.Context(), in); err != nil {
    _ = c.Error(err)
    return
  }
  utils.ResponseOk(c, nil)
}
